<?php
require "admin_header.php";
$data=new Database;
if(isset($_GET['id']))
{
	$maphim=$_GET['id'];
	$sql="select * from phim where maphim='".$maphim."'";
	$data->query($sql);
	while($row=$data->fetch())
	{
		$dt[]=$row;
	}
	$tenphim=$dt[0]['tenphim'];
	$manhasx=$dt[0]['manhasx'];
	$madaodien=$dt[0]['madaodien'];
	$maquocgia=$dt[0]['maquocgia'];
	$machatluong=$dt[0]['machatluong'];
	$machuyenngu=$dt[0]['machuyenngu'];
	$linkanh=$dt[0]['linkanh'];
	$namsx=$dt[0]['namsx'];
	$thoiluong=$dt[0]['thoiluong'];
	$gioithieu=$dt[0]['gioithieu'];
	$ngaydang=$dt[0]['ngaydang'];
	$maloai=$dt[0]['maloai'];
}



if(isset($_POST['btthem']))
{
	if(isset($_SESSION['tenphimmoidang']))
	{
		$sql="update phim set lienket='".$_POST['txturl']."',tentap='".$_POST['txttentap']."' where tenphim='".$_SESSION['tenphimmoidang']."'";
		$data->query($sql);
		unset($_SESSION['tenphimmoidang']);
		echo "<script> window.location='admin_themmoi.php';</script>";
	}
	else
	{
		$tentap=$_POST['txttentap'];
		$lienket=$_POST['txturl'];
		$sql="insert into phim(tenphim,manhasx,madaodien,maquocgia,machatluong,machuyenngu,linkanh,namsx,thoiluong,gioithieu,ngaydang,maloai,lienket,tentap) 
		values('".$tenphim."','".$manhasx."','".$madaodien."','".$maquocgia."','".$machatluong."','".$machuyenngu."','".$linkanh."',
		'".$namsx."','".$thoiluong."','".$gioithieu."','".$ngaydang."','".$maloai."','".$lienket."','".$tentap."')";
		$data->query($sql);
	}
}
?>
<div class="heading">
    <a>Đăng Tập</a>
</div>
<div class="content_page">
<form method="post">
    <table>
        <tr>
            <td>Tên phim:</td>
            <td>
				<?php
					if(isset($_SESSION['tenphimmoidang'])) 
						echo $_SESSION['tenphimmoidang'];
					else
						echo $dt[0]['tenphim'];
				?>
            </td>
        </tr>
        <tr>
            <td> Tên tập:</td><td><input type="text" size="30" name="txttentap" /></td>
        </tr>
        <tr>
            <td> URL:</td><td><input type="url" name="txturl" size="30" /></td>
        </tr>
        <tr>
            <td> </td><td><input type="submit" name="btthem" size="30" value="Thêm Vào" /></td>
        </tr>
    </table>
</form>
</div>
<?php
require "admin_footer.php";
?>